package com.woniuxy.microretailserver.mapper;

import com.woniuxy.microretailserver.bean.GoodsOrderBean;
import com.woniuxy.microretailserver.bean.GoodsOrderExportBean;
import com.woniuxy.microretailserver.bean.GoodsOrderPayExportBean;
import com.woniuxy.microretailserver.bean.PageRequest;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author chenhu
 * 订单商品持久层接口
 */
@Mapper
@Repository
public interface GoodsOrderMapper {
    /**
     * 新增购买订单信息
     *
     * @param goodsOrderBean
     * @return
     */
    @Options(useGeneratedKeys = true, keyProperty = "g.id")
    @Insert("insert into t_goods_order_info" +
            "(order_no,create_time,member_phone,order_money,store,terminal,goods_count,user_name,reduction)" +
            " values(#{g.orderNo},now(),#{g.memberPhone},#{g.orderMoney},#{g.store},#{g.terminal},#{g.goodsCount},#{g.userName},#{g.reduction})")
    int saveGoodsOrder(@Param("g") GoodsOrderBean goodsOrderBean);

    /**
     * 分页查询商品购买订单信息
     * @param request
     * @param goodsOrderBean
     * @return
     */
    List<GoodsOrderBean> findAllGoodsOrder(@Param("p")PageRequest request,@Param("g") GoodsOrderBean goodsOrderBean);

    /**
     * 根据订单号查询订单信息
     * @param orderNo
     * @return
     */
    @Select("select id,order_no,create_time,member_phone,order_money,store,terminal,goods_count,user_name,reduction from t_goods_order_info where order_no=#{orderNo}")
    GoodsOrderBean findByOrderNo(@Param("orderNo") String orderNo);

    /**
     * 分页查询订单及支付信息
     * @param request
     * @param goodsOrderBean
     * @return
     */
    List<GoodsOrderBean> findAllGoodsOrderPay(@Param("pr")PageRequest request,@Param("g") GoodsOrderBean goodsOrderBean);

    /**
     * 导出订单数据
     * @return
     */
    @Select("select * from t_goods_order_info")
    List<GoodsOrderExportBean> findByAll();

    /**
     * 导出订单与账户表数据
     * @return
     */
    @Select("select g.id,g.order_no as orderNo,g.create_time as createTime,g.member_phone as memberPhone,g.order_money,g.store,g.terminal,g.goods_count,g.user_name,g.reduction,p.payment as payment,p.payment_num as paymentNum from " +
            "t_goods_order_info as g,t_pay_info as p where g.id=p.id")
    List<GoodsOrderPayExportBean> findByAllGoodsPay();
}
